

<template>
<h1>计算器练习</h1>
  <input type="text" placeholder="请输入数字1" v-model="n1">
  <input type="text" placeholder="请输入数字2" v-model="n2">
  <br>
<!--  <button   @click="addEmps('+')">加</button>-->
<!--  <button   @click="addEmps('-')">减</button>-->
<!--  <button   @click="addEmps('*')">乘</button>-->
<!--  <button   @click="addEmps('/')">除</button>-->
<!--  <br>-->

<button v-for="item in 4"   @click="addEmps(symbolArr[item-1])">{{symbolsArr[item-1]}}</button>
  <h3>运算结果:{{answer}}</h3>
</template>
<script setup>
let symbolArr = ['+','-','*', '/'];
let symbolsArr = ['加','减' ,'乘','除'];
import {ref} from "vue";

const n1 = ref("");
const n2 = ref("");
const answer =ref("");


console.log(symbolArr[0]);

const addEmps=(item)=>{
  answer.value=eval(n1.value+item+n2.value);
  // let number1 = parseFloat(n1.value);
  // let number2 = parseFloat(n2.value);
  // if (isNaN(number1) || isNaN(number2)){
  //   alert('输数字捏');
  //   return;
  // }
  // console.log(number1);
  // console.log(number2);
  // switch (item){
  //   case 0:
  //     answer.value=number1+number2;
  //     break;
  //   case 1:
  //     answer.value=number1-number2;
  //     break;
  //   case 2:
  //     answer.value=number1*number2;
  //     break;
  //   case 3:
  //     if (number2===0){
  //       alert("除数不能为0");
  //       break;
  //     }
  //     answer.value=number1/number2;
  //     break;
  // }
}


</script>

<style scoped>

</style>